package main

import (
	"flag"
	"fmt"
	"net/http"

	"gitee.com/actor168/gitserver/pkg/config"
	"gitee.com/actor168/gitserver/pkg/router"
	"github.com/gin-gonic/gin"
)

var (
	path = flag.String("conf", "config.yaml", "配置文件路径")
)

func main() {
	flag.Parse()
	config.Init(*path)
	// 启动http server
	s := gin.Default()

	server := http.Server{
		Addr:    fmt.Sprintf(config.Conf.Addr),
		Handler: s,
	}

	{
		s.POST("/gitservice", router.Process)
	}

	// ***************************
	// ----- HTTP Git routes -----
	// ***************************
	{
		s.Any("/:username/:reponame/*path", router.HTTPContexter, router.HTTP, router.RepoRef, router.SingleDownload)
	}
	fmt.Println(server.ListenAndServe())
}
